package me.zhengjie.modules.detail.rest;

import me.zhengjie.annotation.Log;
import me.zhengjie.modules.detail.domain.RealEstateProjectDetail;
import me.zhengjie.modules.detail.service.RealEstateProjectDetailService;
import me.zhengjie.modules.detail.service.dto.RealEstateProjectDetailDto;
import me.zhengjie.modules.detail.service.dto.RealEstateProjectDetailQueryParam;
import me.zhengjie.modules.realestate.domain.RealEstateProject;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Set;

/**
* @author TianI
* @date 2022-02-15
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "房产项目详情管理")
@RequestMapping("/api/realEstateProjectDetail")
public class RealEstateProjectDetailController {

    private final RealEstateProjectDetailService realEstateProjectDetailService;


    @GetMapping("getById/{id}")
    public ResponseEntity getById(@PathVariable Long id){
        RealEstateProjectDetail byId = realEstateProjectDetailService.getById(id);
        return new ResponseEntity<>(byId,HttpStatus.OK);
    }

    @GetMapping
    @Log("查询房产项目详情")
    @ApiOperation("查询房产项目详情")
    @PreAuthorize("@el.check('realEstateProjectDetail:list')")
    public ResponseEntity query(RealEstateProjectDetailQueryParam query, Pageable pageable){
        return new ResponseEntity<>(realEstateProjectDetailService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增房产项目详情")
    @ApiOperation("新增房产项目详情")
    @PreAuthorize("@el.check('realEstateProjectDetail:add')")
    public ResponseEntity create(@Validated @RequestBody RealEstateProjectDetailDto resources){
        return new ResponseEntity<>(realEstateProjectDetailService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改房产项目详情")
    @ApiOperation("修改房产项目详情")
    @PreAuthorize("@el.check('realEstateProjectDetail:edit')")
    public ResponseEntity update(@Validated @RequestBody RealEstateProjectDetailDto resources){
        realEstateProjectDetailService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除房产项目详情")
    @ApiOperation("删除房产项目详情")
    @PreAuthorize("@el.check('realEstateProjectDetail:del')")
    public ResponseEntity delete(@RequestBody Set<Long> ids) {
        realEstateProjectDetailService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }



    /*
    @Log("导出房产项目详情")
    @ApiOperation("导出房产项目详情")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('realEstateProjectDetail:list')")
    public void download(HttpServletResponse response, RealEstateProjectDetailQueryParam query) throws IOException {
        realEstateProjectDetailService.download(realEstateProjectDetailService.queryAll(query), response);
    }*/

}
